#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<stdlib.h>

struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
    
};

void preorder(struct TreeNode* root, int* res, int* returnSize) {

    if (root == NULL) {

        return;

    }

    res[(*returnSize)++] = root->val;
    preorder(root->left, res, returnSize);
    preorder(root->right, res, returnSize);

}

int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    int* res = (int*)malloc(sizeof(int) * 200);
    *returnSize = 0;
    preorder(root, res, returnSize);
    return res;
}


struct TreeNode* BuyNode(int x)
{
    struct TreeNode* node = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    if (node == NULL)
    {
        perror("malloc fail");
        return NULL;
    }

    node->val = x;
    node->left = NULL;
    node->right = NULL;

    return node;
}

int main() {
    struct TreeNode* node1 = BuyNode(1);
    struct TreeNode* node2 = BuyNode(2);
    struct TreeNode* node3 = BuyNode(3);


    node1->right = node2;
    node2->left = node3;
    int* returnSize = 0;
    int* res = preorderTraversal(node1, *returnSize);

    return 0;
}